using System;

namespace Typhone.Public.Security
{
	/// <summary>
	/// Summary description for FunctionNode.
	/// </summary>
	[Serializable]
	public class FunctionNode {
		internal FunctionNode() {
		}

		internal string _functionID;
		internal int _seqNo;
		internal int _layerID;
		internal string _functionPath;
		internal string _appFlag;
		internal string _useFlag;
		internal string _desc;
		private FunctionNode CopyInternal( FunctionNode parentNode ) {
			FunctionNode node = new FunctionNode();

			node._appFlag			= this._appFlag;
			node._functionID		= this._functionID;
			node._functionPath		= this._functionPath;
			node._layerID			= this._layerID;			

			node._seqNo				= this._seqNo;
			node._useFlag			= this._useFlag;
			node._desc				= this._desc;
			node._parentNode		= parentNode;

			if( this.HasChildNode ) {
				foreach( FunctionNode child in this.Nodes ) {
					node.Nodes.Add( child.CopyInternal(this) );
				}
			}
			return node;
		}

		public FunctionNode Copy() {
			return CopyInternal(null);
		}

		internal FunctionNode _parentNode;

		private FunctionNodeCollection _nodes = new FunctionNodeCollection();

		public FunctionNodeCollection Nodes {
			get {
				return _nodes;
			}
		}	

		public bool HasChildNode {
			get {
				return _nodes.Count!=0;
			}
		}

		public string FunctionID {
			get {
				return _functionID;
			}
		}

		public int SeqNo {
			get {
				return _seqNo;
			}
		}

		public int LayerID {
			get {
				return _layerID;
			}
		}

		public string FunctionPath {
			get {
				return _functionPath;
			}
		}


		public string ApproveFlag {
			get {
				return _appFlag;
			}
		}

		public string UsageFlag {
			get {
				return _useFlag;
			}
		}

		public bool IsLastLayer {
			get {
				return _nodes.Count==0;
			}
		}

		public bool IsTopLayer {
			get {
				return this.FunctionID.ToUpper() == "TOP";
			}
		}

		public string Description {
			get {
				//return Globalization.LanguageTable.GetString("FUN_"+this.FunctionID);
				
				return _desc;
			}
		}

		public FunctionNode ParentNode {
			get {
				return _parentNode;
			}
		}
	}
}
